﻿/*
SINACOR - BMF&Bovespa
Arquivo: AlocacaoCoberturaTermo.cs
Criado em: 27-nov-2009 11:59:13
Arquiteto Responsável: ramelo.7comm
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.ServiceModel;
using System.Text;
using Sinacor.Infra.UI.Common;
using Sinacor.Infra.UI.Security.Services;
using Sinacor.UI.Bovespa.Alocacao.Communication.Bovespa.Alocacao.CoberturaTermo;


namespace Sinacor.UI.Bovespa.Alocacao.Communication
{

    /// <summary>
    /// Classe de comunicação com o contrato de serviço AlocacaoCoberturaTermo
    /// </summary>
    public class AlocacaoCoberturaTermo : BaseCommunication
    {

        #region Construtores
        /// <summary>
        /// Construtor parametrizado
        /// </summary>
        /// <param name="sessionInformation"></param>
        public AlocacaoCoberturaTermo(SessionInformation sessionInformation)
            : base(sessionInformation)
        {
        }

        #endregion Construtores

        #region Métodos

        /// <summary>
        /// CobrirOperacoesTermo
        /// </summary>
        /// <param name="request"></param>
        public void CobrirOperacoesTermo(ModelCollection<Model.Operacao> request)
        {
            IAlocacaoCoberturaTermo servico = null;
            try
            {
                using (ServiceInstance<IAlocacaoCoberturaTermo> service = new ServiceInstance<IAlocacaoCoberturaTermo>())
                {
                    servico = service.TryGetInstance(this.Session);
                    servico.CobrirOperacoesTermo(new Translator.ModelToDataContract.AlocacaoCoberturaTermo().ToOperacaoRequest(request));
                }
            }
            catch (Exception ex)
            {
                HandleFault(ex);
            }           
        }

        /// <summary>
        /// ConsultarOperacoes
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public ModelCollection<Model.Operacao> ConsultarOperacoes(Model.Parameter.FiltroCoberturaTermo parameter)
        {
            ModelCollection<Model.Operacao> response = null;

            IAlocacaoCoberturaTermo servico = null;
            try
            {
                using (ServiceInstance<IAlocacaoCoberturaTermo> service = new ServiceInstance<IAlocacaoCoberturaTermo>())
                {
                    servico = service.TryGetInstance(this.Session);
                    response = new Translator.DataContractToModel.AlocacaoCoberturaTermo().ToOperacao(
                        servico.ConsultarOperacoes(
                            new Translator.ModelToDataContract.AlocacaoCoberturaTermo().ToFiltroCoberturaTermoRequest(parameter)));
                }
            }
            catch (Exception ex)
            {
                base.HandleFault(ex);
                //return null;
            }

            return response;
        }

        #endregion Métodos

    }
}